package com.navigationtest.adapt;

import com.navigationtest.Test1Fragment;
import com.navigationtest.Test2Fragment;
import com.navigationtest.Test3Fragment;

import org.jetbrains.annotations.NotNull;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter;

/**
 * User: psn
 * Date: 2021/12/15
 */
public class StartAdapt extends FragmentStateAdapter {
  private   Fragment mfragment;
    public StartAdapt(@NonNull @NotNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
    }

    public StartAdapt(@NonNull @NotNull Fragment fragment) {
        super(fragment);
        this.mfragment =fragment;
    }

    public StartAdapt(@NonNull @NotNull FragmentManager fragmentManager,
                      @NonNull @NotNull Lifecycle lifecycle) {
        super(fragmentManager, lifecycle);
    }

    @NonNull
    @NotNull
    @Override
    public Fragment createFragment(int position) {


        Fragment fragment = null;
        switch (position){
            case 0:{
//                NavController controller = Navigation.findNavController(mfragment.getView());//找到button归属的controller
//                controller.navigate(R.id.action_startFragment_to_test1_fragment);
                fragment = new Test1Fragment();
//                Navigation.findNavController(mfragment.getView()).navigate(R.id.action_global_test1_fragment);
                break;
            }
            case 1:{
//                NavController controller = Navigation.findNavController(mfragment.getView());//找到button归属的controller
//                controller.navigate(R.id.action_startFragment_to_test2Fragment);
                fragment = new Test2Fragment();
//                Navigation.findNavController(mfragment.getView()).navigate(R.id.action_global_test2Fragment);
                break;
            }
            case 2:{
//                NavController controller = Navigation.findNavController(mfragment.getView());//找到button归属的controller

                fragment = new Test3Fragment();
//                Navigation.findNavController(mfragment.getView()).navigate(R.id.action_global_test3Fragment);
                break;
            }
        }
        return fragment;
    }

    @Override
    public int getItemCount() {
        return 3;
    }
}
